{extend name="../../admin/view/main"}

{block name="button"}
<!--{if auth("add")}-->
<button data-open='{:url("add")}' data-title="添加栏目" class='layui-btn layui-btn-sm layui-btn-primary'>添加栏目</button>
<!--{/if}-->
<!--{if auth("add")}-->
<button data-open='{:url("add",["type"=>"page"])}' data-title="添加单页栏目" class='layui-btn layui-btn-sm layui-btn-primary layui-btn-warm'>添加单页栏目</button>
<!--{/if}-->
<!--{if auth("upcache")}-->
<button data-load='{:url("upcache")}' data-title="更新栏目缓存" class='layui-btn layui-btn-sm layui-btn-normal'>更新栏目缓存</button>
<!--{/if}-->
{/block}

{block name="content"}
<div class="layui-tab layui-tab-card think-bg-white">
    <div class="layui-tab-content think-box-shadow">
        <table class="layui-table margin-top-10" lay-skin="line" id="tree-table"></table>
    </div>
</div>
{/block}

{block name='style'}
<style>
.layui-tab-content{ min-height: 700px;}
</style>
{/block}

{block name='script'}
<script>
    var authAdd = '{:auth("add")}',authEdit = '{:auth("edit")}',authDisabled = '{:auth("disabled")}',authRemove = '{:auth("remove")}';
    layui.config({
        base: "__ROOT__/static/plugs/layui/mods/"
    })
    layui.use(['jquery','form', 'treeTable'], function(){
        var treeTable = layui.treeTable;
        treeTable.render({
            elem: '#tree-table',
            data: {$data|raw},
            icon_key: 'name',
            is_checkbox: false,
            parent_key:'parent_id',
            end: function(e){
                form.render();
            },
            cols: [
                {
                    key: 'sort',
                    title: '<button type="button" data-reload class="layui-btn layui-btn-xs">刷 新</button>',
                    width: '100px',
                    css_class: 'list-table-sort-td',
                    template: function(item){
                        return '<label><input data-action-blur="{:request()->url()}" data-value="id#'+item.id+';action#sort;sort#{value}" data-loading="false" value="'+item.sort+'" class="list-sort-input"></label>';
                    }
                },
                {
                    key: 'name',
                    title: '栏目名称',
                    width: '100px',
                    template: function(item){
                        if(item.level == 0){
                            return '<span style="color:red;">'+item.name+'</span>';
                        }else if(item.level == 1){
                            return '<span style="color:green;">'+item.name+'</span>';
                        }else if(item.level >= 2){
                            return '<span style="color:#1E9FFF;">'+item.name+'</span>';
                        }
                    }
                },
                {
                    key: 'description',
                    title: '描述',
                    width: '200px',
                },
                {
                    key: 'modelname',
                    title: '所属模型',
                    width: '100px',
                    align: 'center',
                },
                {
                    key: 'status',
                    title: '状态',
                    width: '100px',
                    align: 'center',
                    template: function(item){
                        if(item.status == 0){
                            return '<span style="color:red;">隐藏</span>';
                        }else if(item.status == 1){
                            return '<span style="color:green;">显示</span>';
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    template: function(item){
                        var op = '';
                        if(parseInt(authAdd)){
                            op += '<a class="layui-btn layui-btn-warm layui-btn-sm" data-title="添加子分类"  data-open=\'{:url("add")}?pid='+item.id+'\'>添加子分类</a>';
                        }
                        if(parseInt(authEdit)){
                            op += '<a class="layui-btn layui-btn-sm" data-title="编辑" data-open=\'{:url("edit")}?mid='+item.modelid+'&pid='+item.parent_id+'&id='+item.id+'\'>编 辑</a>';
                        }
                        if(item.modelid == 0 && !item.haschild){
                            op += '<a class="layui-btn layui-btn-sm layui-btn-normal" data-title="修改内容" data-open=\'{:url("page/edit")}?catid='+item.id+'\'>修改内容</a>';
                        }
                        if(parseInt(authDisabled)){
                            var text = '隐 藏';
                            var btn_class = 'layui-btn-primary';
                            if(item.status == 0){
                                text = '显 示';
                                btn_class = 'layui-btn-normal';
                            }
                            op += '<a class="layui-btn '+btn_class+' layui-btn-sm" data-title="隐藏分类" data-modal=\'{:url("status")}?id='+item.id+'\'>'+text+'</a>';
                        }
                        if(parseInt(authRemove) && !item.haschild){
                            op += '<a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="确定要删除此栏目吗？" data-action="{:url(\'remove\')}" data-value="id#'+item.id+'" data-csrf="{:systoken(\'remove\')}">删 除</a>';
                        }
                        return op;
                    }
                }
            ]
        });

    });
</script>
{/block}